<template>
    <div>
        <h3>新闻列表页面</h3>
        <ul class="mui-table-view" v-for="n in newslist" :key="n.id">
            <li class="mui-table-view-cell mui-media">
                <router-link :to="'/home/newsDetail?id='+n.id">
                    <img class="mui-media-object mui-pull-left" :src="n.img">
                    <div class="mui-media-body">
                        <h1>{{ n.title }}</h1>
                        <p class='mui-ellipsis'>
                            <span>发表时间：{{ n.addTime | dateFormat }}</span>
                            <span>点击：{{n.click}}次</span>
                        </p>
                    </div>
                </router-link>
            </li>


        </ul>
    </div>
</template>
<script>
import {Toast} from "mint-ui";

export default {
    data(){
        return{
            newslist:[]
        }
    }
    ,created() {
        this.getNewsList();
    }
    ,methods:{
        getNewsList(){
            this.$http.get("api/getnewslist").then(result => {
                if (result.status == 200) {
                    // 如果没有失败，应该把数据保存到 data 上
                    console.log( result.body)
                    this.newslist = result.body;
                } else {
                   Toast("获取新闻列表失败！");
                }
            });
        }
    }
}


</script>
<style lang="less" scoped>
    .mui-table-view{
        li{
            h1{font-size:14px;}
            .mui-ellipsis{
                font-size:12px;
                color: #ffb5aa;
                display: flex;
                justify-content: space-between;
            }
        }
    }
</style>